﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class AjaxData_Activity_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string act=Request["action"];
        if (!string.IsNullOrEmpty(act))
        {
            switch (act)
            {
                case "live_save":
                    var live_bl = new Com.Ooohd.Bll.Activity.ZS_Live();
                    var live = live_bl.CreateModel();
                    if (!string.IsNullOrEmpty(Request["lid"])) {
                        live = live_bl.GetSingle(int.Parse(Request["lid"]));
                    }
                    live.Title=Request["title"];
                    live.StartTime = DateTime.Parse(Request["starttime"]);
                    live.EndTime = DateTime.Parse(Request["endtime"]);
                    live.Address=Request["address"];
                    live.Profile=Request["shortdes"];
                    live.HostID=int.Parse(Request["host"]);
                    live.HostNick = new Com.Ooohd.Bll.Activity.ZS_Host().GetSingle(live.HostID).Name;
                    live.Imgs = Request["crs_img"];
                    if (!string.IsNullOrEmpty(Request["lid"]))
                    {
                        live.ID = int.Parse(Request["lid"]);
                        live_bl.Update(live);
                    }
                    else
                    {
                        live.CreateDate = DateTime.Now;
                        live_bl.Add(live);
                    }
                    Response.Write(Common.JSONHelper.ObjectToJSON(new { succ = true,lid=live.ID }));
                    break;
                case "live_detail_save":
                    var live_detail_bl = new Com.Ooohd.Bll.Activity.ZS_LiveDetail();
                    if (string.IsNullOrEmpty(Request["did"]))
                    {
                        var md = live_detail_bl.CreateModel();
                        md.ArtiPart =Common.Input.WipeScript(Request["content"]);
                        md.LiveID = int.Parse(Request["lid"]);
                        md.CreateDate = DateTime.Now;
                        live_detail_bl.Add(md);
                    }
                    else {
                        var md = live_detail_bl.GetSingle(int.Parse(Request["did"]));
                        md.ArtiPart=Common.Input.WipeScript(Request["content"]);
                        live_detail_bl.Update(md);
                    }
                    Response.Write(Common.JSONHelper.ObjectToJSON(new { succ=true}));
                    break;
                case "host_save":
                    var host_bl = new Com.Ooohd.Bll.Activity.ZS_Host();
                    var host = host_bl.CreateModel();
                    host.Name = Request["name"];
                    host.Pic = Request["pic"];
                    if (!string.IsNullOrEmpty(Request["host_id"]))
                    {
                        host.ID = int.Parse(Request["host_id"]);
                        host_bl.Update(host);
                    }
                    else
                        host_bl.Add(host);
                    Response.Write(Common.JSONHelper.ObjectToJSON(new { succ = true }));
                    break;
                case "get":
                    live_bl = new Com.Ooohd.Bll.Activity.ZS_Live();
                    live = live_bl.GetSingle(int.Parse(Request["id"]));
                    live.Title += "^" + live.StartTime.ToString() + "^" + live.EndTime.ToString();
                    Response.Write(Common.JSONHelper.ObjectToJSON(live));
                    break;
                case "v_save":
                    var v_bl = new Com.Ooohd.Bll.Activity.ZS_Video();
                    var video=v_bl.CreateModel();
                    string id = Request["rcid"];
                    if (!string.IsNullOrEmpty(id))
                    {
                        video = v_bl.GetSingle(int.Parse(id));
                    }
                    video.ActDate = DateTime.Parse(Request["actdate"]);
                    video.Company=Request["company"];
                    video.Address=Request["address"];
                    video.Profile=Request["profile"];
                    video.Detail=Common.Input.WipeScript(Request["content"]);
                    video.PreviewImg=Request["previewImg"];
                    if (!string.IsNullOrEmpty(id))
                    {
                        v_bl.Update(video);
                    }
                    else {
                        video.CreateDate = DateTime.Now;
                        v_bl.Add(video);
                    }
                    Response.Write(Common.JSONHelper.ObjectToJSON(new { succ = true }));
                    break;
                case "v_get":
                    v_bl = new Com.Ooohd.Bll.Activity.ZS_Video();
                    video = v_bl.GetSingle(int.Parse(Request["id"]));
                    video.Company += "^" + video.ActDate.ToString();
                    Response.Write(Common.JSONHelper.ObjectToJSON(video));
                    break;
                case "v_del":
                    v_bl = new Com.Ooohd.Bll.Activity.ZS_Video();
                    v_bl.Delete(Request["ids"]);
                    Response.Write(Common.JSONHelper.ObjectToJSON(new { succ = true }));
                    break;
            }
        }
    }
}